package com.wanda.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wanda.model.BuildModel;
import com.wanda.model.JsonGeneralModel;
import com.wanda.model.Pay_TypeModel;
import com.wanda.service.Pay_TypeService;
import com.wanda.util.DateFormat;

@Controller
@RequestMapping("/ht/pay_type")
public class Pay_TypeController {

	@Autowired
	private Pay_TypeService pay_TypeService;
	
	
	//查询所有支付信息
	@RequestMapping(value="/selectAll.do")
	public ModelAndView selectAll(){
		
		System.out.println("进入支付的查询所有方法");
		
		ModelAndView model = new ModelAndView();
		
		List<Pay_TypeModel> pay = null;
		try{
			pay=pay_TypeService.selectAll();
			model.setViewName("/ht/listPay_Type.jsp");
			model.addObject("pay_type", pay);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return model;	
	}
	
	//查询所有开盘信息里用到的
	@RequestMapping(value="/select.do")
	public ModelAndView select(HttpSession session){
		
		System.out.println("进入开盘支付的查询所有方法");
		ModelAndView model = new ModelAndView();
		List<Pay_TypeModel> pay = null;
		try{
			pay=pay_TypeService.selectAll();
			System.out.println("个数："+pay.size());
			model.setViewName("/qt/addPay_Type.jsp");
			model.addObject("pay_type", pay);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		session.setAttribute("payname",pay);
		return model;	
	}
/*	
	//查询所有开盘信息里用到的
	@RequestMapping(value="/selectAllss.do")
	public ModelAndView selectAllss(HttpSession session){
		
		System.out.println("进入开盘支付的查询所有方法");
		String[] str=(String[]) session.getAttribute("checktest");
		System.err.println("sfsfsfsf:"+str);
		ModelAndView model = new ModelAndView();
		List<Pay_TypeModel> pay = null;
		try{
			final List ids = new ArrayList();
			for(String s : str){
				ids.add(s);
				System.out.println("//:"+s);
				session.setAttribute("payname",pay.get(0).getPay_type_name());
			}
			Map map = new HashMap();
			map.put("ids", ids);
			pay=pay_TypeService.selectAllss(map);
			System.out.println("个数："+pay.size());
			model.setViewName("/qt/addPay_Type.jsp");
			model.addObject("pay_type", pay);
		}catch(Exception ex){
			ex.printStackTrace();
		}

		return model;	
	}*/
	
	//付款方式 表 调用所有的支付信息
	public @ResponseBody Map<String,Object> showAlls(String id){
		
		Map<String,Object> map = new HashMap<String,Object>();

		List<Pay_TypeModel> model = null;
		model=pay_TypeService.selectAll();
		map.put("msg",model);
		
		return map;	
	}
		
		//添加付款方式
		@RequestMapping(value="/addPay_Type.do")
		public @ResponseBody Map<String,Object> add(String pay_type_name,String apply_scope,String pay_type_kind,Float explains,String discount,String create_time){
			
			System.out.println("进入添加支付");
			Pay_TypeModel models = new Pay_TypeModel();
			
			models.setPay_type_name(pay_type_name);
			models.setApply_scope(apply_scope);
			models.setPay_type_kind(pay_type_kind);
			models.setDiscount(discount);
			models.setExplains(explains);
			models.setDelete_state("0");
			models.setCreate_time(DateFormat.getNowDate());
			pay_TypeService.insertPay_Type(models);
			
			Map<String,Object> map = new HashMap<String,Object>();
						
			map.put("msg", models);
			return map;		
		}
		
		//修改付款方式
		@RequestMapping(value="/updatePay_Type.do")
		public String update(Pay_TypeModel model){
			
			System.out.println("进入修改付款方式");
		
			model.setUpdate_time(DateFormat.getNowDate());
			pay_TypeService.updatePay_Type(model);
			
			Map<String,Object> map = new HashMap<String,Object>();
			
			map.put("msg", model);
			return "redirect:/ht/pay_type/selectAll.do";
		
		}
		
		//删除付款方式
		@RequestMapping(value="/deletePay_Type.do")
		public String delete(Pay_TypeModel model){
			
			System.out.println("进入支付删除");
			model.setPay_type_id(model.getPay_type_id());
			model.setDelete_time(DateFormat.getNowDate());
			
			int models=pay_TypeService.deletePay_Type(model);
			
            Map<String,Object> map = new HashMap<String,Object>();
			
			map.put("msg", models);
			return "redirect:/ht/pay_type/selectAll.do";
		}
	
		//查询某条付款方式
		@RequestMapping(value="/selectById.do")
		public ModelAndView selectById(String id){
			
			System.out.println("查询某条ID");
			ModelAndView and =new ModelAndView();
			
			Pay_TypeModel model = null;
			try{
				model=pay_TypeService.selectById(id);
				and.setViewName("/ht/updatePay_Type.jsp");
				and.addObject("pay_type", model);
				
			}catch(Exception ex){
				ex.printStackTrace();
			}
			
			return and;
			
		}
}
